#!/usr/bin/python
#-*- coding:utf-8 -*-
import gui
def parse(args, obj):
	args = args[1:]
	opt = ("-ro", "--read-only", "-h", "--help", "-v", "--version", "-b", "--bug")
	ro = False
	if args:
		for arg in args:
			if arg == "-h" or arg == "--help":
				obj.OnCliHelp()
				return 0
			elif arg == "-v" or arg == "--version":
				obj.OnCliVersion()
				return 0
			elif arg == "-ro" or arg == "--read-only":
				ro = True
			elif arg == "-b" or arg == "--bug":
				obj.OnCliBug()
				return 0
			elif (arg[:2] == "--" or arg[:1] == "-") and arg not in opt:
				print "\nInvalid option \""+arg+"\".\nType \"--help\" or \"-h\" for more info.\n"
				return 0
			else:
				if args[args.index(arg) - 1] in opt or arg.index(arg) == 0:
					f = True
				else:
					f = False
				if ro:
					obj.OnOpen(filename=arg, readonly=True, first=f)
				else:
					obj.OnOpen(filename=arg, first=f)
				return 1.0
	else:
		panel = gui.Sheet(obj.nb)
		obj.nb.AddPage(panel, obj.name+repr(obj.untitled))
		obj.nb.SetSelection(obj.nb.GetPageCount() - 1)
		return panel.GetId()